﻿#include "Game.h"
//#include<time.h>

DianJiPai::DianJiPai()
{
    nPlayerID = 0;
    iFlag = 0;
    nType = BASE_PAI::Area_Null;
    nValue = 0;
    //pObject = NULL;
    iID = -1;
}

PokeStep::PokeStep()
{
    bSelfFlag = false;
    bMultipleFlag = false;
    nTotalCount = 0;
    nSelectCount = 0;
    nType = BASE_PAI::Area_Null;

    memset(nSelectType,0,sizeof(nSelectType));
    memset(nSelectValue,0,sizeof(nSelectValue));
}

void _GAME::WaitForChoice()
{
    //return 0;
/*
    int strInput = 0;
	scanf("%d",&strInput);
	if(strInput >= 0 && strInput < 20)			//手牌
	{
		dianjipai.nValue = strInput;
		dianjipai.nPlayerID = w;
        dianjipai.iFlag = m_Player[w].getShouPaiData(dianjipai.nValue)->iFlag;
        dianjipai.nType = BASE_PAI::Area_ShouPai;
        dianjipai.pObject = m_Player[w].getShouPaiData(dianjipai.nValue);
	}
	else if(strInput >= 20 && strInput < 24)	//装备
	{
		dianjipai.nValue = strInput - 20;
		dianjipai.nPlayerID = w;
        dianjipai.iFlag = m_Player[w].getZhuangBeiData(dianjipai.nValue)->iFlag;
        dianjipai.nType = BASE_PAI::Area_ZhuangBei;
        dianjipai.pObject = m_Player[w].getZhuangBeiData(dianjipai.nValue);
	}
	else if(strInput >= 24 && strInput < 30)	//判定区
	{
		dianjipai.nValue = strInput - 24;
		dianjipai.nPlayerID = w;
        dianjipai.iFlag = m_Player[w].getPandingData(dianjipai.nValue)->iFlag;
        dianjipai.nType = BASE_PAI::Area_PanDing;
        dianjipai.pObject = m_Player[w].getPandingData(dianjipai.nValue);
	}
	else if(strInput >= 30 && strInput < 40)	//敌人
	{
		dianjipai.nValue = strInput - 30;
		dianjipai.nPlayerID = -1;
        dianjipai.iFlag = m_Player[dianjipai.nValue].iFlag;
        dianjipai.nType = BASE_PAI::Area_WuJiang;
        dianjipai.pObject = m_Player[dianjipai.nValue].getWujiangData();
	}
	else if(strInput >= 40 && strInput < 43)	//按钮
	{
		dianjipai.nValue = strInput - 40;
		dianjipai.nPlayerID = -1;
		dianjipai.iFlag = pGame->Button[dianjipai.nValue];
        dianjipai.nType = BASE_PAI::Area_Button;
        dianjipai.pObject = NULL;
	}
	else if(strInput == 100)
	{
        for(int i=0; i<m_Player[w].ShouPaiCount; i++)
		{
            if(m_Player[w].getShouPaiData(i)->iValue == GAME_POKE_EMPTY)
				break;
            printf("%d(%d,%d)",i,m_Player[w].getShouPaiData(i)->iValue,m_Player[w].getShouPaiData(i)->iFlag);
		}
        printf("");
        //printf("输入错误");
	}
	else if(strInput == 101)
	{
		for(int i=0; i<4; i++)
		{
            if(m_Player[w].getZhuangBeiData(i) != NULL)
                printf("%d(%d,%d)",i,m_Player[w].getZhuangBeiData(i)->iValue,m_Player[w].getZhuangBeiData(i)->iFlag);
		}
        printf("");
        //printf("输入错误");
	}
	else if(strInput == 102)
	{
		for(int i=0; i<4; i++)
		{
            printf("%d(%d,%d)",i,m_Player[w].getPandingData(i)->iValue,m_Player[w].getPandingData(i)->iFlag);
		}
        printf("");
        //printf("输入错误");
	}
	else if(strInput == 103)
	{
		for(int i=0; i<playerCount; i++)
		{
            printf("%d(%d,%d)",i,m_Player[i].getWujiangData()->iValue,m_Player[i].tili);
		}
        printf("");
        //printf("输入错误");
	}
	/ *
	g_bCanInput = true;
	
	pDlg->SendMessage(WM_USER_REFRESH);
	
	
	InputOverEvent.Lock();
	
	g_bCanInput = false;
	
	pDlg->SendMessage(WM_USER_REFRESH);
	*/
    //return 0;
}


//根据nType,初始化第nStep个步骤
int _GAME::InitAllStatus(int w, _GameChuPaiType eType, int nValue, int nStep, int nParam)
{
    int canSelectValues = 0;    //可以点击的对象数(不包括按钮)
    switch(eType)
	{
    case _GAME::Game_ChuPai_Type_ZhuDong:		//回合内
		{
			switch(nStep)
			{
			case 0:		//第0步
                {
                    resetAllPlayers(getAllPlayers(0));
                    //m_Player[w].flagZhuangBeiByValue(BASE_PAI::Flag_Null,_Pai::Value_All);
                    canSelectValues = m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_All);
                    if( m_Player[w].iSha > 0 )
					{
                        canSelectValues += m_Player[w].flagZhuangBeiByValue(BASE_PAI::Flag_Enable,_Pai::Value_ZhangBa);
                        canSelectValues += m_Player[w].flagZhuangBeiByValue(BASE_PAI::Flag_Enable,_Pai::Value_TanSu);
                    }
					
                    canSelectValues -= m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_Shan);			//闪
                    if(m_Player[w].iTili >= m_Player[w].iTilishangxian)	//桃
                        canSelectValues -= m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_Tao);
                    if( m_Player[w].getPaiCount(_Pai::Value_ShanDian,BASE_PAI::Area_PanDing) == 1 )	//闪电
                        canSelectValues -= m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_ShanDian);
                    if( m_Player[w].iSha <= 0 &&						//杀+诸葛连弩
                        !(m_Player[w].getZhuangBeiData(BASE_PAI::Area_WuQi) != NULL &&
                        m_Player[w].getZhuangBeiData(BASE_PAI::Area_WuQi)->value() == _Pai::Value_LianNu))
					{
                        canSelectValues -= m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_Sha);
					}
                    if(EnableAllPlayersByZhuangBei(w,_Pai::Value_All,true) == 0)  //借刀
                        m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_JieDao);

                    FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable);
                    HidePlayersArea();

					step[nStep].bSelfFlag = true;
					step[nStep].bMultipleFlag = false;
					step[nStep].nTotalCount = 1;
                    step[nStep].nType = BASE_PAI::Area_ShouPai | BASE_PAI::Area_ZhuangBei;

                    Debug(_T("%1武将可选手牌数为:%2").arg(w).arg(canSelectValues));

                    shortMsg = msgHash[_Pai::Value_All][0];
                    ShowChuPaiMessage(shortMsg);
					
					
					//初始化所有
					//牌的状态
                    //此步骤的step[nStep]的各个内容
				}
                break;
            default:	//处理第1~n步
				{
                    if(step[0].nSelectType[0] == BASE_PAI::Area_ZhuangBei)		//选的是武器
					{
                        switch(m_Player[w].getZhuangBeiData((BASE_PAI::_Areas)step[0].nSelectValue[0])->value())
						{
                        case _Pai::Value_ZhangBa:
							{
								switch(nStep)		//第几步
								{
								case 1:
									{
                                       canSelectValues =  ChuPai_ZhangBa(w,nStep,eType);
									}
                                    break;
                                case 2:
                                    {
                                    FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;

                                        canSelectValues = EnableAllPlayersByDistent(w,2);

                                        shortMsg = msgHash[_Pai::Value_Sha][0]
                                                .arg(_Pai::getName(_Pai::Value_Sha));
                                                //.arg(_Pai::getName(_Pai::Value_ZhangBa));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 3:
                                    {

                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_Sha));
                                    }
                                    break;
                                }
							}
                            break;
                        case _Pai::Value_TanSu:
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        canSelectValues = ChuPai_TanSu(w,nStep,eType);
                                    }
                                    break;
                                case 2:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;

                                        canSelectValues = EnableAllPlayersByDistent(w,2);

                                        shortMsg = msgHash[_Pai::Value_Sha][0]
                                                .arg(_Pai::getName(_Pai::Value_Sha));
                                        ShowChuPaiMessage(shortMsg);
                                                //.arg(_Pai::getName(_Pai::Value_TanSu));
                                    }
                                    break;
                                case 3:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_Sha));
                                    }
                                    break;
                                }
                            }
                            break;
                        default:
                            Err(_T("InitAllStatus Err"));
                            setGameStatus(Game_Status_Err);
                            break;
                        }
					}
                    else if(step[0].nSelectType[0] == BASE_PAI::Area_ShouPai)	//选的是手牌
					{
                        switch(m_Player[w].getShouPaiData(step[0].nSelectValue[0])->value())
                        {
                        case _Pai::Value_Sha:				//选的是杀
							{
								switch(nStep)		//第几步
								{
								case 1:
									{
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);
										
										step[nStep].bSelfFlag = false;
										step[nStep].bMultipleFlag = false;
										step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;

                                        canSelectValues = EnableAllPlayersByDistent(w,2);

                                        shortMsg = msgHash[_Pai::Value_Sha][0]
                                                .arg(_Pai::getName(_Pai::Value_Sha));
                                        ShowChuPaiMessage(shortMsg);
									}
                                    break;
								case 2:
									{
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);
										
										step[nStep].bSelfFlag = true;
										step[nStep].bMultipleFlag = false;
										step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_Sha));
									}
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_Tao:				//选的是桃
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_Tao));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_Shun:				//选的是顺
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;




                                        QList<_Player*> list = EnableAllPlayersByDistent(w,1);

                                        list = flagAllPlayersByPaiCount(list, BASE_PAI::Flag_Null, 1);
                                        list = retainPlayer(list, BASE_PAI::Flag_Enable);
                                        canSelectValues = list.length();

                                        shortMsg = msgHash[_Pai::Value_Shun][0]
                                                .arg(_Pai::getName(_Pai::Value_Shun));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 2:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_ShouPai | BASE_PAI::Area_ZhuangBei | BASE_PAI::Area_PanDing;

                                        canSelectValues = m_Player[step[1].nSelectPlayerID].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_All);
                                        canSelectValues += m_Player[step[1].nSelectPlayerID].flagZhuangBeiByValue(BASE_PAI::Flag_Enable,_Pai::Value_All);
                                        canSelectValues += m_Player[step[1].nSelectPlayerID].flagPanDing(BASE_PAI::Flag_Enable,_Pai::Value_All);

                                        if(m_Player[w].isMe())
                                            ShowPlayersArea(step[1].nSelectPlayerID);

                                        shortMsg = msgHash[_Pai::Value_Shun][1]
                                                .arg(_Pai::getName(_Pai::Value_Shun));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 3:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_Shun));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_Chai:				//选的是拆
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;

                                        canSelectValues = FlagAllPlayersByPaiCount(BASE_PAI::Flag_Enable, 1, w, false, 0);

                                        shortMsg = msgHash[_Pai::Value_Chai][0]
                                                .arg(_Pai::getName(_Pai::Value_Chai));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 2:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_ShouPai | BASE_PAI::Area_ZhuangBei | BASE_PAI::Area_PanDing;

                                        canSelectValues = m_Player[step[1].nSelectPlayerID].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_All);
                                        canSelectValues += m_Player[step[1].nSelectPlayerID].flagZhuangBeiByValue(BASE_PAI::Flag_Enable,_Pai::Value_All);
                                        canSelectValues += m_Player[step[1].nSelectPlayerID].flagPanDing(BASE_PAI::Flag_Enable,_Pai::Value_All);

                                        if(m_Player[w].isMe())
                                            ShowPlayersArea(step[1].nSelectPlayerID);

                                        shortMsg = msgHash[_Pai::Value_Chai][1]
                                                .arg(_Pai::getName(_Pai::Value_Chai));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 3:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_Chai));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_WuZhong: //无中
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_WuZhong));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_JieDao:      //借刀
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        canSelectValues = 0;
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;

                                        canSelectValues = EnableAllPlayersByZhuangBei(w,_Pai::Value_All);
                                        int i = GetNextPlayer(w);
                                        for(; i != w; i = GetNextPlayer(i))
                                        {
                                            if(m_Player[i].getZhuangBeiData(BASE_PAI::Area_WuQi) == NULL)continue;
                                            m_Player[i].setAFlag(BASE_PAI::Flag_Enable);
                                            canSelectValues ++;

                                        }

                                        shortMsg = msgHash[_Pai::Value_JieDao][0]
                                                .arg(_Pai::getName(_Pai::Value_JieDao));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 2:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;

                                        canSelectValues = EnableAllPlayersByDistent(step[1].nSelectPlayerID,2);

                                        shortMsg = msgHash[_Pai::Value_JieDao][1]
                                                .arg(_Pai::getName(_Pai::Value_JieDao));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 3:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_Sha));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_WanJian: //万剑
                            {
                                switch(nStep)
                                {
                                case 1:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_WanJian));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_NanMan:  //南蛮
                            {
                                switch(nStep)
                                {
                                case 1:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_NanMan));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_GaoKao:	//高考
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;

                                        flagAllPlayers(removePlayer(getAllPlayers(0),w), BASE_PAI::Flag_Enable,BASE_PAI::FlagType_Add);

                                        shortMsg = msgHash[_Pai::Value_GaoKao][0]
                                                .arg(_Pai::getName(_Pai::Value_GaoKao));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 2:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_GaoKao));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_ShanDian:	//选的是闪电
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_ShanDian));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_LeBuSiShu:   //乐不思蜀
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = false;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_WuJiang;


                                        QList<_Player*> list = flagAllPlayers(removePlayer(getAllPlayers(0),w), BASE_PAI::Flag_Enable,BASE_PAI::FlagType_Set);
                                        list = retainPlayer(list, BASE_PAI::Flag_Enable);
                                        flagAllPlayersByPanDing(list, BASE_PAI::Flag_Null,_Pai::Value_LeBuSiShu);
                                        list = retainPlayer(list, BASE_PAI::Flag_Enable);
                                        canSelectValues = list.length();

                                        shortMsg = msgHash[_Pai::Value_LeBuSiShu][0]
                                                .arg(_Pai::getName(_Pai::Value_LeBuSiShu));
                                        ShowChuPaiMessage(shortMsg);
                                    }
                                    break;
                                case 2:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = _T("使用%1")
                                        //        .arg(_Pai::getName(_Pai::Value_LeBuSiShu));
                                    }
                                    break;
                                }
                            }
                            break;
                        case _Pai::Value_LianNu:				//选的是武器
                        case _Pai::Value_ZhangBa:
                        case _Pai::Value_QingLong:
                        case _Pai::Value_GuanShiFu:
                        case _Pai::Value_HanBing:
                        case _Pai::Value_TanSu:
                            {
                                switch(nStep)		//第几步
                                {
                                case 1:
                                    {
                                        canSelectValues = 3;
                                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                        step[nStep].bSelfFlag = true;
                                        step[nStep].bMultipleFlag = false;
                                        step[nStep].nTotalCount = 1;
                                        step[nStep].nType = BASE_PAI::Area_Button;

                                        //shortMsg = msgHash[_Pai::Value_LianNu][0]
                                        //        .arg(_Pai::getName(m_Player[w].getShouPaiData(step[0].nSelectValue[0])->value()));
                                    }
                                    break;
                                }
                            }
                            break;
                        default:
                            Err(_T("InitAllStatus Err2"));
                            setGameStatus(Game_Status_Err);
                            break;
						}
					}
					break;
				}
			}
		}
		break;
    case _GAME::Game_ChuPai_Type_BeiDong:    //被动出牌
		{
			switch(nValue)
			{
            case _Pai::Value_Sha:
				{
					switch(nStep)
					{
					case 0:
                        {
                            flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,BASE_PAI::FlagType_Set);

                            m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_All);
                            canSelectValues = m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_Sha);
                            canSelectValues += m_Player[w].flagZhuangBeiByValue(BASE_PAI::Flag_Enable,_Pai::Value_ZhangBa);
                            canSelectValues += m_Player[w].flagZhuangBeiByValue(BASE_PAI::Flag_Enable,_Pai::Value_TanSu);

                            FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);

                            step[nStep].bSelfFlag = true;
                            step[nStep].bMultipleFlag = false;
                            step[nStep].nTotalCount = 1;
                            step[nStep].nType = BASE_PAI::Area_ShouPai | BASE_PAI::Area_ZhuangBei;

                            //shortMsg = msgHash[_Pai::Value_Sha][1]
                            //        .arg(_Pai::getName(_Pai::Value_Sha));
                            //ShowChuPaiMessage(shortMsg);
						}
                        break;
                    //第一步选的是武器还是手牌杀
                    default:
                        {
                            if(step[0].nSelectType[0] == BASE_PAI::Area_ZhuangBei)		//选的是武器
                            {
                                switch(m_Player[w].getZhuangBeiData((BASE_PAI::_Areas)step[0].nSelectValue[0])->value())
                                {
                                case _Pai::Value_ZhangBa:
                                    {
                                        switch(nStep)		//第几步
                                        {
                                        case 1:
                                            {
                                                canSelectValues = ChuPai_ZhangBa(w,nStep,eType);
                                            }
                                            break;
                                        case 2:
                                            {
                                                canSelectValues = 3;
                                                FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                                step[nStep].bSelfFlag = true;
                                                step[nStep].bMultipleFlag = false;
                                                step[nStep].nTotalCount = 1;
                                                step[nStep].nType = BASE_PAI::Area_Button;

                                                //shortMsg = _T("%1确定?")
                                                //        .arg(_Pai::getName(_Pai::Value_Sha));
                                            }
                                            break;
                                        }
                                    }
                                    break;
                                case _Pai::Value_TanSu:
                                    {
                                        switch(nStep)		//第几步
                                        {
                                        case 1:
                                            {
                                                canSelectValues = ChuPai_TanSu(w,nStep,eType);
                                            }
                                            break;
                                        case 2:
                                            {
                                                canSelectValues = 3;
                                                FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                                step[nStep].bSelfFlag = true;
                                                step[nStep].bMultipleFlag = false;
                                                step[nStep].nTotalCount = 1;
                                                step[nStep].nType = BASE_PAI::Area_Button;

                                                //shortMsg = _T("%1确定?")
                                                //        .arg(_Pai::getName(_Pai::Value_Sha));
                                            }
                                            break;
                                        }
                                    }
                                    break;
                                default:
                                    Err(_T("InitAllStatus Err"));
                                    setGameStatus(Game_Status_Err);
                                    break;
                                }
                            }
                            else if(step[0].nSelectType[0] == BASE_PAI::Area_ShouPai)	//选的是手牌
                            {
                                switch(m_Player[w].getShouPaiData(step[0].nSelectValue[0])->value())
                                {
                                case _Pai::Value_Sha:				//选的是杀
                                    {
                                        switch(nStep)		//第几步
                                        {
                                        case 1:
                                            {
                                                canSelectValues = 3;
                                                FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);

                                                step[nStep].bSelfFlag = true;
                                                step[nStep].bMultipleFlag = false;
                                                step[nStep].nTotalCount = 1;
                                                step[nStep].nType = BASE_PAI::Area_Button;

                                                //shortMsg = _T("%1确定?")
                                                //        .arg(_Pai::getName(_Pai::Value_Sha));
                                            }
                                            break;
                                        }
                                    }
                                    break;
                                default:
                                    Err(_T("InitAllStatus Err"));
                                    setGameStatus(Game_Status_Err);
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
                break;
            case _Pai::Value_Shan:
				{
					switch(nStep)
					{
					case 0:
						{
                            flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,BASE_PAI::FlagType_Set);

                            m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_All);
                            canSelectValues = m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_Shan);			//闪
                            FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);
							
							step[nStep].bSelfFlag = true;
							step[nStep].bMultipleFlag = false;
							step[nStep].nTotalCount = 1;
                            step[nStep].nType = BASE_PAI::Area_ShouPai;
							
                            //shortMsg = msgHash[_Pai::Value_Shan][0]
                            //        .arg(_Pai::getName(_Pai::Value_Shan));
						}
						break;
					case 1:
						{
                            canSelectValues = 2;
                            FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);
							
							step[nStep].bSelfFlag = true;
							step[nStep].bMultipleFlag = false;
							step[nStep].nTotalCount = 1;
                            step[nStep].nType = BASE_PAI::Area_Button;
							
                            //shortMsg = _T("%1确定?")
                            //        .arg(_Pai::getName(_Pai::Value_Shan));
						}
                        break;
					default:
						{
                            Debug("err");
						}
						break;
					}
				}
				break;
            case _Pai::Value_Tao:
                {
                    switch(nStep)
                    {
                    case 0:
                        {
                            flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,BASE_PAI::FlagType_Set);

                            m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_All);
                            canSelectValues = m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_Tao);			//闪
                            FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);

                            step[nStep].bSelfFlag = true;
                            step[nStep].bMultipleFlag = false;
                            step[nStep].nTotalCount = 1;
                            step[nStep].nType = BASE_PAI::Area_ShouPai;

                            shortMsg = msgHash[_Pai::Value_Tao][0]
                                    .arg(_Pai::getName(_Pai::Value_Tao));
                            ShowChuPaiMessage(shortMsg);
                        }
                        break;
                    case 1:
                        {
                            canSelectValues = 2;
                            FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);

                            step[nStep].bSelfFlag = true;
                            step[nStep].bMultipleFlag = false;
                            step[nStep].nTotalCount = 1;
                            step[nStep].nType = BASE_PAI::Area_Button;

                            //shortMsg = _T("%1确定?")
                            //        .arg(_Pai::getName(_Pai::Value_Tao));
                        }
                        break;
                    default:
                        {
                            Debug("err");
                        }
                        break;
                    }
				}
                break;
            case _Pai::Value_GuanShiFu:    //弃牌
                {
                    switch(nStep)
                    {
                    case 0:
                        flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,BASE_PAI::FlagType_Set);

                        m_Player[w].flagZhuangBeiByArea(BASE_PAI::Flag_Null,BASE_PAI::Area_WuQi,BASE_PAI::FlagType_Set);
                        canSelectValues = m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_All);
                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);


                        step[nStep].bSelfFlag = true;
                        step[nStep].bMultipleFlag = true;
                        step[nStep].nTotalCount = 2;
                        step[nStep].nType = BASE_PAI::Area_ShouPai;

                        shortMsg = msgHash[_Pai::Value_GuanShiFu][0];
                               //.arg(_Pai::getName(_Pai::Value_GuanShiFu));
                        ShowChuPaiMessage(shortMsg);

                        break;
                    case 1:
                        canSelectValues = 2;
                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);

                        step[nStep].bSelfFlag = true;
                        step[nStep].bMultipleFlag = false;
                        step[nStep].nTotalCount = 1;
                        step[nStep].nType = BASE_PAI::Area_Button;

                        //shortMsg = _T("(弃牌)确定?");
                        break;
                    default:
                        Err("Err3");
                        break;
                    }
                }
                break;
            case _Pai::Value_HanBing:
                {
                    switch(nStep)
                    {
                    case 0:
                        flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,BASE_PAI::FlagType_Set);

                        m_Player[iMyID].resetAllFlags();

                        canSelectValues = m_Player[nParam].flagZhuangBeiByArea(BASE_PAI::Flag_Enable,BASE_PAI::Area_WuQi,BASE_PAI::FlagType_Set);
                        canSelectValues += m_Player[nParam].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_All);
                        canSelectValues += m_Player[nParam].flagPanDing(BASE_PAI::Flag_Enable,_Pai::Value_All);
                        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);


                        step[nStep].bSelfFlag = false;
                        step[nStep].bMultipleFlag = true;
                        step[nStep].nTotalCount = 2;
                        step[nStep].nType = BASE_PAI::Area_ShouPai | BASE_PAI::Area_ZhuangBei | BASE_PAI::Area_PanDing;


                        if(m_Player[w].isMe())
                            ShowPlayersArea(nParam);

                        shortMsg = msgHash[_Pai::Value_HanBing][0];
                               //.arg(_Pai::getName(_Pai::Value_GuanShiFu));
                        ShowChuPaiMessage(shortMsg);

                        break;
                    case 1:
                        canSelectValues = 2;
                        FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);

                        step[nStep].bSelfFlag = true;
                        step[nStep].bMultipleFlag = false;
                        step[nStep].nTotalCount = 1;
                        step[nStep].nType = BASE_PAI::Area_Button;

                        //shortMsg = _T("选择确定可以弃掉对方任意两张手牌，取消则继续造成伤害");
                        break;
                    default:
                        Err("Err3");
                        break;
                    }
                }
                break;
			default:
                {
                    Err("BeiDongChuPai Err");
                }
                break;
			}
		}
		break;
    case _GAME::Game_ChuPai_Type_QiPai:    //弃牌
		{
			switch(nStep)
			{
			case 0:
                flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,BASE_PAI::FlagType_Set);

                m_Player[w].flagZhuangBeiByValue(BASE_PAI::Flag_Null,_Pai::Value_All);
                canSelectValues = m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_All);
                FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);
				
				
				step[nStep].bSelfFlag = true;
				step[nStep].bMultipleFlag = true;
				step[nStep].nTotalCount = nValue;
                step[nStep].nType = BASE_PAI::Area_ShouPai;
				
                shortMsg = msgHash[_Pai::Value_All][1]
                        .arg(nValue);
                ShowChuPaiMessage(shortMsg);

				break;
			case 1:
                canSelectValues = 2;
                FlagMenus(BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);
				
				step[nStep].bSelfFlag = true;
				step[nStep].bMultipleFlag = false;
				step[nStep].nTotalCount = 1;
                step[nStep].nType = BASE_PAI::Area_Button;
				
                //shortMsg = _T("弃牌确定?");
				break;
			default:
                Err("Err3");
				break;
			}
		}
        break;
    default:
        Err("InitAllStatus Err3");
        setGameStatus(Game_Status_Err);
        break;
	}
    return canSelectValues;
}

/*
int _GAME::ResetAllFlags()		//将已点选的重新设置
{
	int i = 0;
	for(; i < playerNum; i++)
	{
		int j = 0;
        for(; j < m_Player[i].ShouPaiCount; j++)
		{
            m_Player[i].ShouPai[j].iFlag = BASE_PAI::Flag_Null;
		}
        m_Player[i].TouXiang.iFlag = BASE_PAI::Flag_Null;
		
	}
	for(;i < 3; i++)
	{
        Button[i].iFlag = BASE_PAI::Flag_Null;
	}
	return 0;
}
*/


_GAME::_GameButtonValue _GAME::ChuPai(int w, _GameChuPaiType eType, int nValue, int nParam)
{
    int		nStep = 0;          //目前是第几步骤
    int		iIndex = -1;		//回退模式(保存到要回退的第几步骤),0表示不回退
    bool	bInitFlag = false;  //是否已经初始化过(false表示需要刷新)
    int     canChoiceCount = 0;
    _GameButtonValue     ret = Game_Button_Err;           //返回值
	memset(step,0,sizeof(step));

    //startChuPai(w);

    if(m_Player[w].isComputer())
        Sleep(config.configHash["DELAY_TIME_COMPUTER"].toInt());
    while(1)        //一次出牌循环
	{
		if(!bInitFlag)
		{
            canChoiceCount = InitAllStatus(w,eType,nValue,nStep,nParam);		//规划步骤,设置显示是否可点击
			bInitFlag = true;
		}
        if(iIndex >= nStep)				//回退,重新从第0步骤开始刷新牌
		{
			RefreshAllFlags(nStep);		//将已点选的重新设置

            //还不是本次选择步骤,则继续刷新
			if(iIndex > nStep)
            {
				nStep++;
				bInitFlag = false;
				continue;
			}
		}

		iIndex = -1;

        for(;;)     //点击一张牌
        {
            if(m_Player[w].isMe())
            {
                //ComputerChuPai(-1,0,0,Game_ChuPai_Type_ZhuDong,-1);
                //RefreshUI();
                emit s_RefreshAllFlags();
                //emit s_RefreshAllPokePosition();
                WaitForChoice();
                CheckGameOver();
            }
            else if(m_Player[w].isComputer())
            {
                //stopChuPai(w);
                if(eType == _GAME::Game_ChuPai_Type_QiPai)  //电脑弃牌
                {
                    dianjipai.nType = BASE_PAI::Area_Button;
                    dianjipai.nValue = Game_Button_Cancel;
                    break;
                }
                else    //电脑出牌
                {
                    ComputerChuPai(w, nStep, canChoiceCount, eType, nValue);
                    CheckGameOver();
                }
            }

            if(dianjipai.iFlag & BASE_PAI::Flag_Enable)
				break;
        }

        if(dianjipai.nType == BASE_PAI::Area_Button)	//按钮
        {
            //stopChuPai(w);
            if(dianjipai.nValue == Game_Button_Cancel)
            {
                //自动弃牌
                if(eType == _GAME::Game_ChuPai_Type_QiPai)
                {
                    ComputerQiPai(w,nValue);
                    ret = Game_Button_OK;
                }
                else if(eType == _GAME::Game_ChuPai_Type_ZhuDong)
                {
                    memset(step,0,sizeof(step));
                    nStep = 0;
                    iIndex = -1;
                    bInitFlag = false;
                    continue;
                }
                else if(eType == _GAME::Game_ChuPai_Type_BeiDong)
                {
                    ret = Game_Button_Cancel;
                }
            }
            else
                ret = (_GameButtonValue)dianjipai.nValue;

            iIndex = -1;


            //全部置NULL
            flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,BASE_PAI::FlagType_Set);
            m_Player[iMyID].flagZhuangBeiByValue(BASE_PAI::Flag_Null,_Pai::Value_All);
            m_Player[iMyID].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_All);
            FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Null,BASE_PAI::Flag_Null);
            HidePlayersArea();
            emit s_RefreshAllFlags();
            //emit s_RefreshAllPokePosition();

            break;//end while(1)
		}

        //倒序遍历每个步骤
        int i = nStep;
        for(; i >= 0; i--)
        {
            bool bChoiceType = dianjipai.nType & step[i].nType; //包含 要选的类型

            //如果选择的类型是武将,则不判断bSelfFlag
            if(bChoiceType && (dianjipai.nType != BASE_PAI::Area_WuJiang))
            {
                bChoiceType = ((step[i].bSelfFlag && dianjipai.nPlayerID == w)
                                        || (!step[i].bSelfFlag && dianjipai.nPlayerID != w));
            }

            //是要选的类型
            if(bChoiceType)
            {
                if(dianjipai.iFlag & BASE_PAI::Flag_Clicked)	//已点,则:找到,取消,个数-1,改变状态
                {
                    for(int j = 0; j < step[i].nSelectCount; j++)	//遍历值
                    {
                        if(dianjipai.nValue == step[i].nSelectValue[j])	//找到值
                        {
                            //删掉值
                            for(int k = j; k < step[i].nSelectCount - 1; k++)
                            {
                                step[i].nSelectValue[k] = step[i].nSelectValue[k+1];
                                step[i].nSelectType[k] = step[i].nSelectType[k+1];
                            }
                            step[i].nSelectCount--;
                            dianjipai.pObject->clearAFlag(BASE_PAI::Flag_Clicked);

                            //如果是单选 或 不是本步骤要选的,则回退
                            if(!step[i].bMultipleFlag || i != nStep)
                            {
                                iIndex = i;
                                nStep = 0;
                                bInitFlag = false;
                            }

                            //如果是多选且本轮要选的
                            else
                            {
                                //选够,下一步骤
                                if(step[i].nSelectCount == step[i].nTotalCount)
                                {
                                    iIndex = 0;
                                    nStep++;
                                    bInitFlag = false;
                                }
                                //没有选够,继续选
                                else
                                {
                                    iIndex = 0;
                                    bInitFlag = true;
                                }
                            }
                            i = -2; //处理完毕,退出(i作为标记了)
                            break;
                        }
                    }   //end for
                    if(i == -2)break;
                    else continue;      //不是本回合
                }
                else//	未点,则:
                {
                    dianjipai.pObject->setAFlag(BASE_PAI::Flag_Clicked);
                    //单张,切换并刷新
                    if(!step[i].bMultipleFlag)
                    {
                        if(step[i].nSelectCount != 0)
                        {
                            iIndex = i + 1;
                            nStep = 0;
                            bInitFlag = false;
                        }
                        else
                        {
                            iIndex = 0;
                            nStep ++;
                            bInitFlag = false;
                        }
                        step[i].nSelectCount = 0;
                    }
                    //多张
                    else
                    {
                        //选够,下一步
                        if(step[i].nSelectCount == step[i].nTotalCount - 1)
                        {
                            iIndex = 0;
                            nStep++;
                            bInitFlag = false;
                        }
                        else //没够
                        {
                            //此次出牌阶段,不刷新
                            if(i == nStep)
                            {
                                iIndex = 0;
                                //iIndex = nStep - 1;
                                bInitFlag = true;
                            }
                            //非此次阶段,重新刷新
                            else
                            {
                                iIndex = i;
                                nStep = 0;
                                bInitFlag = false;
                            }
                        }
                    }

                    //保存
                    if(!(dianjipai.iFlag & BASE_PAI::Flag_Enable))	//牌 状态
                    {
                        Debug("Error!!!");
                    }
                    step[i].nSelectValue[step[i].nSelectCount] = dianjipai.nValue;
                    step[i].nSelectType[step[i].nSelectCount] = dianjipai.nType;
                    step[i].nSelectPlayerID = dianjipai.nPlayerID;		//牌 所属玩家ID
                    step[i].nSelectCount++;
//                    if(dianjipai.nType == BASE_PAI::Area_Button)	//按钮,直接返回
//                    {
//                        flagAllPlayers(getAllPlayers(0), BASE_PAI::Flag_Null,0);
//                        m_Player[iMyID].flagZhuangBeiByValue(BASE_PAI::Flag_Null,_Pai::Value_All);
//                        m_Player[iMyID].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_All);

//                        //stopChuPai(w);
//                        ret = dianjipai.nValue;
//                        break;
//                    }
                    break;
                }
            }
            else		//类型不同,则将此步骤取消
            {
                step[i].nSelectCount = 0;
            }
        }       //end for
        if(i == -1)Debug(_T("Err255"));  //没找到类型
        if(ret != Game_Button_Err)       //按钮,这步好像运行不到
            break;

        if(iIndex >= 0)continue;    //开始下一轮或刷新
        else if(iIndex == -1)break; //这步好像运行不到
    }

    //stopChuPai(w);
    return (_GameButtonValue)ret;

}


int	_GAME::RefreshAllFlags(int nStep)
{
    for(int i = 0; i < step[nStep].nSelectCount; i++)
    {
        switch(step[nStep].nSelectType[i])
        {
        case BASE_PAI::Area_WuJiang:
            {
                m_Player[step[nStep].nSelectValue[i]].setAFlag(BASE_PAI::Flag_Clicked);
            }
            break;
        case BASE_PAI::Area_ZhuangBei:
            {
                m_Player[step[nStep].nSelectPlayerID].getZhuangBeiData((BASE_PAI::_Areas)step[nStep].nSelectValue[i])->setAFlag(BASE_PAI::Flag_Clicked);
            }
            break;
        case BASE_PAI::Area_PanDing:
            {
                m_Player[step[nStep].nSelectPlayerID].getPandingData(step[nStep].nSelectValue[i])->setAFlag(BASE_PAI::Flag_Clicked);
            }
            break;
        case BASE_PAI::Area_ShouPai:
            {
                m_Player[step[nStep].nSelectPlayerID].getShouPaiData(step[nStep].nSelectValue[i])->setAFlag(BASE_PAI::Flag_Clicked);
            }
            break;
        //case POKE_TYPE_JINENG:
        default:
            {
                //Debug("Error!!!!!");
            }
            break;
        }
    }

	/*
	int i = 0;
	for(; i <= nStep; i++)
	{
		for(int j = 0; j < step[i].nSelectCount; j++)
		{
			switch(step[i].nType)
			{
			case POKE_TYPE_SHOUPAI:
                m_Player[0].ShouPai[j].nFlag ^= BASE_PAI::Flag_Clicked;
			case POKE_TYPE_PLAYER:
                m_Player[0].
			}
		}
	}
	*/
	return 0;
}

int _GAME::ChuPai_ZhangBa(int w, int nStep, _GameChuPaiType eType)
{
    int canSelectValues =
            m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_All);

    if(eType == Game_ChuPai_Type_ZhuDong)
        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);
    else
        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);

    step[nStep].bSelfFlag = true;
    step[nStep].bMultipleFlag = true;
    step[nStep].nTotalCount = 2;
    step[nStep].nType = BASE_PAI::Area_ShouPai;

    shortMsg = msgHash[_Pai::Value_ZhangBa][0]
            .arg(_Pai::getName(_Pai::Value_Sha));
            //.arg(_Pai::getName(_Pai::Value_ZhangBa));
    ShowChuPaiMessage(shortMsg);
    return canSelectValues;
}

int _GAME::ChuPai_TanSu(int w, int nStep, _GameChuPaiType eType)
{
    m_Player[w].flagShouPai(BASE_PAI::Flag_Null,_Pai::Value_All);
    int canSelectValues =
            m_Player[w].flagShouPai(BASE_PAI::Flag_Enable,_Pai::Value_Sha);

    if(eType == Game_ChuPai_Type_ZhuDong)
        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Enable);
    else
        FlagMenus(BASE_PAI::Flag_Null,BASE_PAI::Flag_Enable,BASE_PAI::Flag_Null);

    step[nStep].bSelfFlag = true;
    step[nStep].bMultipleFlag = true;
    step[nStep].nTotalCount = 2;
    step[nStep].nType = BASE_PAI::Area_ShouPai;

    shortMsg = msgHash[_Pai::Value_TanSu][0]
            .arg(_Pai::getName(_Pai::Value_Sha));
            //.arg(_Pai::getName(_Pai::Value_TanSu));
    ShowChuPaiMessage(shortMsg);
    return canSelectValues;
}
